//
// Created by Administrator on 2024/3/11.
//

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'

void solve() {
    int n, m;
    while (cin >> n >> m) {
        vector<int> a(n);
        for (int i = 1; i <= n; i++) {
            a[i - 1] = i;
        }
        int t = 0;
        while (a.size() != 1) {
            int p = a.size();
            t = (t + m - 1) % p;
            a.erase(a.begin() + t);
        }
        cout << a[0] << "\n";
    }

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    // cin>>t;
    while (t--) {
        solve();
    }
    return 0;
}